﻿using System;
using Ninject;
using SSTU.Management.Dependency;

namespace SSTU.ViewModel.Core
{
	/// <summary>
	/// Class-locator for all vie models.
	/// </summary>
	public class ViewModelLocator : ViewModelBase
	{
		private TimeTableMenuViewModel _timeTableMenuViewModel;
		private FacultyMenuViewModel _departmentMenuViewModel;
		private GroupTimeTableViewModel _groupTimeTableViewModel;

		/// <summary>
		/// Create instance of locator.
		/// </summary>
		public ViewModelLocator()
		{
			if (DependencyContainer.Current.IsInitialized)
			{
				OnDependencyContainerInitialized();
			}
			DependencyContainer.Current.Initialized += OnDependencyContainerInitialized;
		}

		/// <summary>
		/// Method calls when dependency container is initialized.
		/// </summary>
		private void OnDependencyContainerInitialized()
		{
			TimeTableMenuViewModel = DependencyContainer.Current.Kernel.Get<TimeTableMenuViewModel>();
			FacultyMenuViewModel = DependencyContainer.Current.Kernel.Get<FacultyMenuViewModel>();
			GroupTimeTableViewModel = DependencyContainer.Current.Kernel.Get<GroupTimeTableViewModel>();
		}

		/// <summary>
		/// Gets or sets view model for time table main menu.
		/// </summary>
		public TimeTableMenuViewModel TimeTableMenuViewModel
		{
			get { return _timeTableMenuViewModel; }
			set
			{
				if (value != _timeTableMenuViewModel)
				{
					RaisePropertyChanging<TimeTableMenuViewModel>(() => TimeTableMenuViewModel);
					_timeTableMenuViewModel = value;
					RaisePropertyChanged<TimeTableMenuViewModel>(() => TimeTableMenuViewModel);
				}
			}
		}

		/// <summary>
		/// Gets or sets view model for faculty menu.
		/// </summary>
		public FacultyMenuViewModel FacultyMenuViewModel
		{
			get { return _departmentMenuViewModel; }
			set
			{
				if (value != _departmentMenuViewModel)
				{
					RaisePropertyChanging<FacultyMenuViewModel>(() => FacultyMenuViewModel);
					_departmentMenuViewModel = value;
					RaisePropertyChanged<FacultyMenuViewModel>(() => FacultyMenuViewModel);
				}
			}
		}

		/// <summary>
		/// Gets or sets view model for group time table.
		/// </summary>
		public GroupTimeTableViewModel GroupTimeTableViewModel
		{
			get { return _groupTimeTableViewModel; }
			set
			{
				if (value != _groupTimeTableViewModel)
				{
					RaisePropertyChanging<GroupTimeTableViewModel>(() => GroupTimeTableViewModel);
					_groupTimeTableViewModel = value;
					RaisePropertyChanged<GroupTimeTableViewModel>(() => GroupTimeTableViewModel);
				}
			}
		}
	}
}
